package com.zero.manage.web.utils.validated;

import com.zero.manage.web.components.entity.rbac.SysPowerEntity;
import io.gitee.zerowsh.enums.ToolEnums;
import org.hibernate.validator.spi.group.DefaultGroupSequenceProvider;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class SysPowerGroupSequenceProvider implements DefaultGroupSequenceProvider<SysPowerEntity> {

    @Override
    public List<Class<?>> getValidationGroups(SysPowerEntity bean) {
        List<Class<?>> defaultGroupSequence = new ArrayList<>();
        defaultGroupSequence.add(SysPowerEntity.class); // 这一步不能省,否则Default分组都不会执行了，会抛错的

        if (bean != null) { // 这块判空请务必要做
            ToolEnums.PowerTypeEnums type = bean.getType();
            if (Objects.equals(type, ToolEnums.PowerTypeEnums.MENU)) {
                defaultGroupSequence.add(SysPowerEntity.PathGroup.class);
            } else if (Objects.equals(type, ToolEnums.PowerTypeEnums.POWER)) {
                defaultGroupSequence.add(SysPowerEntity.UrlGroup.class);
                defaultGroupSequence.add(SysPowerEntity.ParentGroup.class);
            }
        }
        return defaultGroupSequence;
    }
}
